/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package localization;

import java.util.Iterator;

/**
 *
 * @author KAV
 */
public class Localization {

    private static short resourceUid; // текущая применяемая локализация
    private static Iterable<LocalizationResource> resources;
    private static String helpFileName;

    public static void setResources(Iterable<LocalizationResource> resources) {
        Localization.resources=resources;
    }

    public static Iterable<LocalizationResource> getResources() {
        return resources;
    }

    public static LocalizationResource getResource(short uid) {
        Iterator<LocalizationResource> locRecourseIter = resources.iterator();
        while (locRecourseIter.hasNext()) {
            LocalizationResource locRecourse = locRecourseIter.next();
            if (locRecourse.getUid() == uid) {
                return locRecourse;
            }
        }
        return null;
    }

    public static void bind(short uid) {
        resourceUid = uid;
        helpFileName=getResource(uid).getHelpFileName();
    }// { resourceUid = uid}

    public static short getResourceUid() {
        return resourceUid;
    }

    public static String getString(String name) {
        LocalizationResource res = getResource(resourceUid);
        Object o = res.getString(name);
        if (o != null)
            return (String) o;
        else
            return "TODO : localization";
    }
    public static String getHelpFileName(){
        return helpFileName;
    }
}
